﻿<?php
// 设置最大生命周期为10000小时
ini_set('session.gc_maxlifetime', 36000000);
// 设置Cookie生命周期为10000小时
ini_set('session.cookie_lifetime', 36000000);

session_start();
header("Content-type: text/html; charset=utf-8");
date_default_timezone_set('Asia/Shanghai');
error_reporting(0);

// 文件路径及变量定义
define('STRING_DELIMITED', '{I~N!T@E#R$V%A^L}');
define('ROOT_PATH', dirname(__FILE__));
define('JS_PATH', 'js/');
define('CSS_PATH', 'css/');
define('IMAGE_PATH', 'images/');
define('AJAX_PATH', 'ajax/');
define('COUNTRY_IMAGE', 'flags/');


require_once(ROOT_PATH . "/conf/db.php");
require_once(ROOT_PATH . "/class/db.class.php");
require_once(ROOT_PATH . "/conf/function.php");


// 设置默认语言
$lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'CN';
$lang_file = ROOT_PATH . "/lang/$lang.json";
// 加载语言文件
if (file_exists($lang_file)) {
    $translations = json_decode(file_get_contents($lang_file), true);
} else {
    $translations = json_decode(file_get_contents(ROOT_PATH . "/lang/zh.json"), true);
}
// 全局翻译函数
function t($key) {
    global $translations;

    return isset($translations[$key]) ? $translations[$key] : $key;
}
// 定义语言相关的 CSS class
$css_class = ($lang === 'CN') ? 'pangmen' : 'poppin';
// 检测语言切换请求
if (isset($_GET['lang'])) {
	$_SESSION['lang'] = $_GET['lang'];
	header("Location: " . $_SERVER['PHP_SELF'] . "?nocache=" . time()); // 防止缓存
	exit;
}



// 数据库初始化
$db = new db();
$dbprefix = "";

// 获取比赛信息
$mt_id = ($_GET['mt_id']) ? $_GET['mt_id'] : 4579;
if (is_numeric($mt_id)) {
    $sql = "SELECT mt_cn_name, mt_en_name, mt_round, mt_round_num, mt_cr_id, mt_sts FROM `match` WHERE mt_id = '$mt_id' LIMIT 1";
    $res = $db->SelectSQL($sql);
    $num = count($res);

    if ($num > 0) {
        $match_cn_name = ($lang === 'CN')?'劳力士中国青少年冠军锦标赛': 'Rolex China Junior Championship'; // $res[0]['mt_cn_name'];
        $match_en_name = 'Rolex China Junior Championship'; // $res[0]['mt_en_name'];
        $rd_id = (is_numeric($_GET['rd_id'])) ? $_GET['rd_id'] : $res[0]['mt_round'];
        $cr_id = $res[0]['mt_cr_id'];
        $maxRound = $res[0]['mt_round_num'];
        $course = getCourse($cr_id);
        $mt_sts = $res[0]['mt_sts'];
        $pars = getPar($mt_id); // 标准杆信息
        $players = matchPlayer($mt_id); // 参赛球员信息
        $mt_round = $res[0]['mt_round']; // 当前轮次
        $course_name = ($lang === 'CN')?'深圳观澜湖高尔夫球会':'Mission Hills Golf Club Shenzhen'; // $course[$cr_id];
    } else {
        echo '暂无比赛';
        exit;
    }

    if (empty($mt_id) || !is_numeric($mt_id)) {
        echo "参数错误，无法获取信息！";
        exit;
    }
} else {
    echo '暂无比赛';
    exit;
}
?>